var SCRIBEFIRE_TOP = {
    init : function () {
        try {
            var container = parent.gBrowser.tabContainer;
            container.addEventListener("TabClose", SCRIBEFIRE_TOP.watchForZemantaPrefs, false);
        } catch (notSplitScreen) {
        }
    },
    
    destroy : function () {
        try {
            var container = parent.gBrowser.tabContainer;
            container.removeEventListener("TabClose", SCRIBEFIRE_TOP.watchForZemantaPrefs, false);
        } catch (notSplitScreen) {
        }
    },
    
    watchForZemantaPrefs : function (event) {
        // browser is the XUL element of the browser that's been removed
        var browser = event.target.linkedBrowser;
        
        if (browser.contentDocument.location.href.match(/https?:\/\/prefs.zemanta.com\//i)) {
            performancingEditor.getCurrentEditorWindow().SF_ZEMANTA.getZemantaPrefs();
        }
    }
};

addEventListener("load", function () { SCRIBEFIRE_TOP.init(); }, false);
addEventListener("unload", function () { SCRIBEFIRE_TOP.destroy(); }, false);
